package com.yf.tool;

import cn.hutool.core.bean.BeanUtil;
import com.yf.constants.VvHanConstants;
import com.yf.tool.context.ToolBaseContext;
import com.yf.tool.model.dto.WeatherResponseDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.model.ToolContext;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;

import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * VvHanTools -- vv han code : 522
 *
 * @author : YiFei
 * @since : 2025/5/19 00:26
 */
@Deprecated
@Component
@RequiredArgsConstructor
public class WeatherTool implements BiFunction<Void, ToolContext, WeatherResponseDTO> {

    private final RestClient restClient = RestClient.create();

    /**
     * 获取天气信息
     *
     * @param toolContext the function argument
     * @return WeatherResponseDTO
     */
    @Deprecated
    @Override
    public WeatherResponseDTO apply(Void unused, ToolContext toolContext) {
        ToolBaseContext toolContextDTO = BeanUtil.toBean(toolContext.getContext(), ToolBaseContext.class);
        return restClient.get()
                .uri(VvHanConstants.VV_HAN_HOST + VvHanConstants.BaseInfoEnums.WEATHER.getUrl() + "?ip={ip}", toolContextDTO.getIp())
                .retrieve()
                .body(WeatherResponseDTO.class);
    }
}